package com.nmwlw.demo.ui

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import com.nmwlw.demo.R
import com.nmwlw.demo.data.DataSource.IndexOptions
import com.nmwlw.demo.data.enums.NIC700Screen

@Preview()
@Composable
fun ButtonPreview () {
    MenuButton(R.string.index_set_common,{})
}
@Preview()
@Composable
fun setsPreview () {
//    SetsScreen(IndexOptions,Unit)
}


/**
 * 设置按钮页面布局
 */
@Composable
fun SetsScreen(
    itemList : List<Pair<Int, Int>>,
    navController: NavHostController
) {
    LazyVerticalGrid(
        columns = GridCells.Fixed(4),
        modifier = Modifier.padding(16.dp),
        verticalArrangement = Arrangement.spacedBy(16.dp),
        horizontalArrangement = Arrangement.spacedBy(16.dp)
    ) {
        items(itemList) {
            item -> MenuButton(
                btnItemNameId = item.first,
                onClick = {
                    if (item.second == 1) {
                        navController.navigate(NIC700Screen.SETS_COMMON_SET.name)
                    }else if (item.second == 2) {
                        navController.navigate(NIC700Screen.SETS_COM_SERIAL.name)
                    }else if (item.second == 3) {
                        navController.navigate(NIC700Screen.WEBVIEW_TEST.name)
                    }
                }
            )
        }
    }
}

/**
 * 菜单按钮
 */
@Composable
fun MenuButton(
    @StringRes btnItemNameId: Int,
    onClick: () ->Unit,
) {
    Button(
        onClick = onClick,
        modifier = Modifier
            .aspectRatio(16f/13f),
        shape = RoundedCornerShape(16.dp),
        colors = ButtonDefaults.buttonColors(
            containerColor = Color(0xFFFFA500)
        ),
        contentPadding = PaddingValues(0.dp)
    ) {
        Box(
            modifier = Modifier.fillMaxSize(),
            contentAlignment = Alignment.Center
        ) {
            Text(
                text = stringResource(btnItemNameId),
                fontSize = 16.sp,
                color = Color.White,
                fontWeight = FontWeight.Bold
            )
        }
    }
}



